<template>
  <el-card style="width: 26%;display: flex;justify-content: center;align-items: end">
    <el-button v-if="canSign" @click="sign" :loading="signLoading">立即签到</el-button>
    <el-button v-else disabled>今日已签到</el-button>
  </el-card>
</template>
<script setup>
import {userSign, querySigned} from "@/views/system/user/js/UserSignRequest.js";
import {onMounted, ref} from "vue";
import {ElMessage} from "element-plus";

onMounted(() => {
  reqQuerySigned()
})

const canSign = ref(true);
const signLoading = ref(false);
const sign = () => {
  signLoading.value = true;
  userSign().then(res => {
    canSign.value = !res.success
    if (res.success) {
      ElMessage.success("签到成功")
    }
  }).finally(() => {
    signLoading.value = false;
  })
}

const reqQuerySigned = () => {
  querySigned().then(res => {
    canSign.value = !res.data
  })
}
</script>
<style scoped>

</style>